package barinadroid.game;

import java.util.Timer;
import java.util.TimerTask;

public class CoolDown
{
	private boolean isCoolingDown;
	private final Timer timer;
	private final float delay;

	public CoolDown(float delay)
	{
		timer = new Timer();
		this.delay = delay;
		isCoolingDown = false;
	}

	public boolean IsCoolingDown()
	{
		return this.isCoolingDown;
	}

	/**
	 * Will start cooling down if necessary.
	 * 
	 * @returns if was cooling down before entering Start()
	 */
	public boolean Start()
	{
		boolean wasCollingDown = IsCoolingDown();
		if(!IsCoolingDown())
		{
			this.isCoolingDown = true;
			timer.schedule(new TimerTask()
			{
				@Override
				public void run()
				{
					isCoolingDown = false;
				}
			}, (long)delay);
		}
		return wasCollingDown;
	}
}